package com.interview.candidate.controller;

import com.interview.candidate.domain.entity.CandidateInfo;
import com.interview.candidate.service.ICandidateInfoService;
import com.interview.common.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author zzw
 * @date 2025/5/31
 * @description 面试者控制器
 */
@Slf4j
@Tag(name = "候选人管理")
@RestController
@RequestMapping("/candidate")
public class CandidateInfoController {

    @Autowired
    private ICandidateInfoService candidateInfoService;

    /**
     * 新增面试者
     */
    @Operation(summary = "创建候选人")
    @PostMapping("/add")
    public Result<String> add(@Parameter(description = "候选人信息") @RequestBody CandidateInfo candidateInfo) {
        log.info("新增面试者,{}", candidateInfo);
        candidateInfoService.save(candidateInfo);
        return Result.success();
    }

    /**
     * 修改面试者
     */
    @Operation(summary = "修改候选人")
    @PutMapping("/update")
    public Result<String> update(@Parameter(description = "候选人信息") @RequestBody CandidateInfo candidateInfo) {
        log.info("修改面试者,{}", candidateInfo);
        candidateInfoService.updateById(candidateInfo);
        return Result.success();
    }

    /**
     * 删除面试者
     */
    @Operation(summary = "删除候选人")
    @DeleteMapping("/delete/{id}")
    public Result<String> delete(@Parameter(description = "候选人id") @PathVariable("id") String id) {
        log.info("删除面试者,{}", id);
        candidateInfoService.removeById(id);
        return Result.success();
    }

    /**
     * 查询面试者
     */
    @Operation(summary = "查询候选人")
    @GetMapping("/query/{id}")
    public Result<CandidateInfo> query(@Parameter(description = "候选人id") @PathVariable("id") String id) {
        log.info("查询面试者,{}", id);
        return Result.success(candidateInfoService.getById(id));
    }

    @Operation(summary = "查询所有候选人")
    @GetMapping("/queryAll")
    public Result<List<CandidateInfo>> queryAll() {
        log.info("查询所有面试者");
        return Result.success(candidateInfoService.list());
    }
}
